package com.liu.communitysystemend.module.ParkingSpace.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.communitysystemend.module.ParkingSpace.domain.ParkingSpace;
import com.liu.communitysystemend.module.ParkingSpace.domain.QPackingSpaceDto;
import com.liu.communitysystemend.module.ParkingSpace.service.ParkingSpaceService;
import com.liu.communitysystemend.module.room.domain.Room;
import com.liu.communitysystemend.module.room.domain.RoomDto;
import com.liu.communitysystemend.module.user.domain.User;
import com.liu.communitysystemend.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liu
 * @create 2023-03-17 21:08
 */
@RestController
@RequestMapping("/api/parkingSpace")
public class ParkingSpaceController {
    @Autowired
    private ParkingSpaceService parkingSpaceService;

    @ApiOperation("更新来访信息")
    @GetMapping("/get/{id}")
    public Result<ParkingSpace> getComplaints(@PathVariable("id") String id) {
        return Result.success(parkingSpaceService.getVisitorById(id));
    }

    @ApiOperation("更新来访信息")
    @PostMapping("modify")
    public Result<ParkingSpace> save(@RequestBody ParkingSpace parkingSpace) {
        return Result.success(parkingSpaceService.update(parkingSpace));
    }

    @ApiOperation("添加来访信息")
    @PostMapping("add")
    public Result<ParkingSpace> add(@RequestBody ParkingSpace parkingSpace) {
        return Result.success(parkingSpaceService.add(parkingSpace));
    }

    @ApiOperation("查询来访列表(分页)")
    @PostMapping("page")
    public Result<Page<ParkingSpace>> getPage(@RequestBody ParkingSpace parkingSpace) {
        return Result.success(parkingSpaceService.getPage(parkingSpace));
    }

    @GetMapping("delete/{id}")
    @ApiOperation("删除来访")
    public Result deleteById(@PathVariable("id") String id) {
        return parkingSpaceService.deleteById(id) > 0 ? Result.success() : Result.failed();
    }

    @ApiOperation("来访test")
    @GetMapping("/test")
    public Result test() {
        return Result.success(parkingSpaceService.test());
    }

    @ApiOperation("获取车位列表")
    @PostMapping("list")
    public Result<List<ParkingSpace>> getList(@RequestBody ParkingSpace parkingSpace) {
        return Result.success(parkingSpaceService.getList(parkingSpace));

    }

    @ApiOperation("车位详情")
    @GetMapping("checkInfo/{id}")
    public Result<User> CheckInfo(@PathVariable("id") String id) {
        return Result.success(parkingSpaceService.CheckInfo(id));
    }
    @ApiOperation("登记")
    @PostMapping("checkIn")
    public Result checkIn(@RequestBody QPackingSpaceDto qPackingSpaceDto){
        return Result.success(parkingSpaceService.checkIn(qPackingSpaceDto));
    }

    @ApiOperation("退停车位")
    @PostMapping("checkOut")
    public Result checkOut(@RequestBody QPackingSpaceDto qPackingSpaceDto){
        return Result.success(parkingSpaceService.checkOut(qPackingSpaceDto));
    }



}


